<template>
  <!-- 修改资料 -->

  <div>
    <el-form
      label-width="85px"
      :model="form"
      label-position="right"
      ref="formRef"
      :rules="formRules"
    >
      <el-row>
        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
          <el-form-item label="编号" prop="number">
            <el-input v-model="form.number"></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
          <el-form-item label="名称" prop="name">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
          <el-form-item label="小数位数" prop="digits">
            <el-input-number v-model="form.digits" :min="0" />
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
          <el-form-item label="状态">
            <el-switch
              v-model="form.status"
              active-value="normal"
              inactive-value="disabled"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="button-position">
      <el-button @click="updateVisible">取 消</el-button>
      <el-button type="primary" @click="updateUnit(formRef)">确 定</el-button>
    </div>
  </div>
</template>
    
  <script setup>
import { reactive, ref, onMounted } from "vue";
import { ElNotification } from "element-plus";
import { Check, Close } from "@element-plus/icons-vue";
import Api from "@/api/model/pm";
const emit = defineEmits(["updatetable"]);
// 添加用户数据的对象
const form = ref({});
const formRef = ref();
const formRules = reactive({
  number: [{ required: true, message: "请输入编号", trigger: "blur" }],
  name: [{ required: true, message: "请输入名称", trigger: "blur" }],
});
const props = defineProps({
  paramsData: {
    type: Object,
    defalut: {},
  },
});
onMounted(() => {
  getInit();
});
const getInit = async () => {
  let res = await Api.unit.detail.post(props.paramsData);
  if (res.code == "200") {
    form.value = res.data;
  }
};
const updateVisible = (val) => {
  emit("updatetable");
};

const restAddFormData = () => {
  formRef.value.resetFields();
};

// 上传
const updateUnit = async (formRef) => {
  await formRef.validate((valid, fields) => {
    if (valid) {
      updateUnitData();
    }
  });
};

const updateUnitData = async () => {
  // console.log(form.name);
  var params = {
    bean: form.value,
  };
  console.log(form.value);
  var res = await Api.unit.update.post(params);
  console.log(res);
  if (res.code == 200) {
    restAddFormData();
    ElNotification.success({
      title: "",
      message: "添加成功！",
      duration: 2000,
    });
    emit("updatetable", true);
  }
};
</script>
    
  <style scoped></style>
    
    